﻿package ui;


import java.rmi.RemoteException;

import javax.swing.JComboBox;
import javax.swing.JLabel;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;


import salesManagerLogic.MockSalesManagerLogic;
import vo.salesManager.BookQueryPanelVO;
import vo.salesManager.OrderQueryPanelVO;

import logicInterface.SalesManagerLogicInterface;
import main.Main;


public class OrderQueryPanel extends MyPanel{

	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	private JLabel orderlistLabel;
	private JLabel ordersearchLabel;
	private DefaultTableModel orderdtm;
	private JTable orderlist;
	private JScrollPane orderjsp;
	private JTextField ordersearchField;
	private JLabel orderclassLabel;
	private JComboBox orderclassComboBox;
	private JComboBox stateComboBox;
	private MyButton ordersearchButton;
	private MyButton hasSendButton;


	protected void initComponent() {
		try {
			Main.getLogic().searchOrder();
		} catch (RemoteException e1) {
			e1.printStackTrace();
		}
		OrderQueryPanelVO oqpvo=null;
		try {
			oqpvo = Main.getLogic().getOqpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		
		this.setBounds(300, 150, 700, 450);
		orderlistLabel = new JLabel("未签收订单列表：");
		ordersearchLabel = new JLabel("精确查找：");
		orderdtm = new DefaultTableModel(oqpvo.getOrderData(),new String[]{"订单编号","所属用户","价格","状态","下单时间"});
		orderlist = new JTable(orderdtm);
		DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// 设置table内容居中
		tcr.setHorizontalAlignment(SwingConstants.CENTER);
		orderlist.setDefaultRenderer(Object.class, tcr);
		orderjsp = new JScrollPane(orderlist);
		orderjsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		ordersearchField = new JTextField();
		orderclassLabel = new JLabel("类别：");
		orderclassComboBox = new JComboBox(new String[]{"所属用户"});
		stateComboBox=new JComboBox(new String[]{"刚下单","仓库配货","物流配送","已签收"});
		ordersearchButton = new MyButton("精确查找");
		hasSendButton = new MyButton("更改状态");
		orderlistLabel.setBounds(10, 20, 120, 20);
		ordersearchLabel.setBounds(400, 20, 100, 20);
		orderjsp.setBounds(10, 40, 350, 300);
		ordersearchField.setBounds(390, 50, 200, 25);
		orderclassLabel.setBounds(390, 100, 80, 20);
		orderclassComboBox.setBounds(490, 100, 100, 20);
		ordersearchButton.setBounds(480, 200, 100, 40);
		stateComboBox.setBounds(450, 280, 120, 40);
		hasSendButton.setBounds(600, 280, 120, 40);
		this.add(orderlistLabel);
		this.add(ordersearchLabel);
		this.add(orderjsp);
		this.add(ordersearchField);
		this.add(orderclassLabel);
		this.add(orderclassComboBox);
		this.add(ordersearchButton);
		this.add(hasSendButton);
		this.add(stateComboBox);
		
		logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toMain");
		ordersearchButton.setButtonAction("searchOrder");
		hasSendButton.setButtonAction("hasSend");

	}


	@Override
	protected void updateVO() {
		OrderQueryPanelVO oqpvo=null;
		try {
			oqpvo = Main.getLogic().getOqpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		oqpvo.setKeyword(ordersearchField.getText());
		oqpvo.setKeywordType(orderclassComboBox.getSelectedIndex());
		oqpvo.setSelectedRow(orderlist.getSelectedRow());
		oqpvo.setState(stateComboBox.getSelectedIndex());
		try {
			Main.getLogic().setOqpvo(oqpvo);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
	
	

}
